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
4 Posts 4 Posters 29 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.
  • N Offline
    N Offline
    Nano Tape
    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 B X 3 Replies Last reply
    0
    • N Nano Tape

      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

      It looks reasonable to me. The only thing I would say is that it is generally better to start loop counters from zero, as they are often used to access array items:

      for (int firstNum = 0; firstNum < 12; firstNum ++) {
      answerNum = firstNum * secondNum;
      System.out.println(firstNum + " x " + secondNum + " = " + answerNum);
      }

      Also try to use consistent indentation, as it makes your code much easier to read. I don't know which tutorials you have been working on but The Java™ Tutorials[^] are some of the best for a beginner.

      1 Reply Last reply
      0
      • N Nano Tape

        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);
          }
        }
        

        }

        B Offline
        B Offline
        banumadhu
        wrote on last edited by
        #3

        Useful article which was very helpful. also interesting and contains good information. Python programming language has advanced data structures and effective object-oriented programming concept that allows the developers to write concepts in fewer links than other programming languages. The simple syntax and dynamic typing feature make python as ideal programming language for scripting and rapid application development in many platforms. This programming language is used in leading companies like Google, Yahoo, CERN and even in NASA. If you are new or just need brush-up with python programming language, you can consider taking python training in chennai using the below link. Python Training in chennai

        1 Reply Last reply
        0
        • N Nano Tape

          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);
            }
          }
          

          }

          X Offline
          X Offline
          xrcwrn
          wrote on last edited by
          #4

          Yes you have done great work. I think you want to know have you done correct process(steps) in correct way. This process is known as algorithm in computer programming( c,c++, java etc). First write your steps in notebook or in notepad. then follow the steps. This is the general process for implementing any program.

          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