So I only VERY recently got into what people call "coding", especially Java. Here's what I've made with my teeny tiny hands. Basically, you input a year, and it converts it into centuries:
import java.util.Scanner;
public class somemaths {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Please insert a year:");
int str = sc.nextInt();
int calc1 = (str+99)/100;
if (str>0) {
System.out.print("This is the " + calc1);
int unity = calc1%10;
if (unity>=4)
System.out.print("th century. I'm sure of it!");
if (unity==3)
System.out.print("rd century. I'm sure of it!");
if (unity==2)
System.out.print("nd century. I'm sure of it!");
if (unity==1)
System.out.print("st century. I'm sure of it!");
}
else
System.out.print("Please don't input negative numbers :c");
}
}
Questions are:
1) Eclipse tells me that 'sc' is never closed. What is this about?
2) Is the code itself okay-ish?
3) This is probably the noobiest question I'll ever ask, but how can I create a window with a dialog and a text box (as in, a box where you can input some numbers), and then show the result in another dialog window? I've vaguely heard of JOptionPane.showMessageDialog before, but I just don't know how to apply it here.
Thanks a bunch!