Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Java
  4. My First Java

My First Java

Scheduled Pinned Locked Moved Java
questionjava
3 Posts 2 Posters 9 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MallardsReach
    wrote on last edited by
    #1

    Hi and thanks for looking, Just started to learn Java and after reading various tutorials came up with this simple tables program. My question, is it as it should be? I mean it works OK but is it coded correctly?

    import java.util.Scanner; // Import the Scanner class
    public class MyTables {
    public static void main(String[] args) {
    int secondNum, answerNum;

    Scanner sc = new Scanner(System.in);  // Create a Scanner object
    System.out.println("Type a number:");
    secondNum = sc.nextInt(); // Read user input	
    
    for (int firstNum = 1; firstNum <= 12; firstNum ++) { 
    answerNum = firstNum \* secondNum;
    System.out.println(firstNum + " x " + secondNum + " = " + answerNum);
      }
    }
    

    }

    L 1 Reply Last reply
    0
    • M MallardsReach

      Hi and thanks for looking, Just started to learn Java and after reading various tutorials came up with this simple tables program. My question, is it as it should be? I mean it works OK but is it coded correctly?

      import java.util.Scanner; // Import the Scanner class
      public class MyTables {
      public static void main(String[] args) {
      int secondNum, answerNum;

      Scanner sc = new Scanner(System.in);  // Create a Scanner object
      System.out.println("Type a number:");
      secondNum = sc.nextInt(); // Read user input	
      
      for (int firstNum = 1; firstNum <= 12; firstNum ++) { 
      answerNum = firstNum \* secondNum;
      System.out.println(firstNum + " x " + secondNum + " = " + answerNum);
        }
      }
      

      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Looks OK and works, so that should be enough. You may like to use formatting on your output so all table entries are on the same column - currently the x and beyond is shifted right from 10 onwards.

      M 1 Reply Last reply
      0
      • L Lost User

        Looks OK and works, so that should be enough. You may like to use formatting on your output so all table entries are on the same column - currently the x and beyond is shifted right from 10 onwards.

        M Offline
        M Offline
        MallardsReach
        wrote on last edited by
        #3

        Thanks for the reply and for the suggestion re formatting.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups