1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
timofeeve [1]
3 years ago
13

Write a java program to print the following series: 1 5 9 13 17...n terms​

Computers and Technology
2 answers:
andrew11 [14]3 years ago
6 0

Answer:

In Java:

import java.util.*;

public class Main{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int n;

System.out.print("Max of series: ");

n = input.nextInt();

for(int i = 1; i<=n;i+=4){

    System.out.print(i+" ");

}

}

}

Explanation:

This declares n as integer. n represents the maximum of the series

int n;

This prompts the user for maximum of the series

System.out.print("Max of series: ");

This gets user input for n

n = input.nextInt();

The following iteration prints from 1 to n, with an increment of 4

<em> for(int i = 1; i<=n;i+=4){</em>

<em>     System.out.print(i+" ");</em>

<em>}</em>

trapecia [35]3 years ago
4 0

Answer:

In Java:

import java.util.*;

public class Main{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int n;

System.out.print("Max of series: ");

n = input.nextInt();

for(int i = 1; i<=n;i+=4){

   System.out.print(i+" ");

}

}

}

Explanation:

This declares n as integer. n represents the maximum of the series

int n;

This prompts the user for maximum of the series

System.out.print("Max of series: ");

This gets user input for n

n = input.nextInt();

The following iteration prints from 1 to n, with an increment of 4

for(int i = 1; i<=n;i+=4){

   System.out.print(i+" ");In Java:

import java.util.*;

public class Main{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int n;

System.out.print("Max of series: ");

n = input.nextInt();

for(int i = 1; i<=n;i+=4){

   System.out.print(i+" ");

}

}

}

Explanation:

This declares n as integer. n represents the maximum of the series

int n;

This prompts the user for maximum of the series

System.out.print("Max of series: ");

This gets user input for n

n = input.nextInt();

The following iteration prints from 1 to n, with an increment of 4

for(int i = 1; i<=n;i+=4){

   System.out.print(i+" ");

}

Explanation:

You might be interested in
Please help with this:
Tanzania [10]

Answer:

I'm not gonna give you the answer. I want you to think about this what is math, what is science, how does it help the world, and etc. These are some example questions to help.

Explanation:

5 0
2 years ago
Coupon collector is a classic statistic problem with many practical applications. The problem is to pick objects from a set of o
ahrayia [7]

Answer:

Here is the JAVA program:

public class Main {  //class name

public static void main(String[] args) {   //start of main method

//sets all boolean type variables spades, hearts diamonds and clubs to false initially

   boolean spades = false;  

   boolean hearts = false;

   boolean diamonds = false;

   boolean clubs = false;  

   String[] deck = new String[4];  //to store card sequence

   int index = 0;  //to store index position

   int NoOfPicks = 0;  //to store number of picks (picks count)

   while (!spades || !hearts || !diamonds || !clubs) {   //loop starts

       String card = printCard(getRandomCard());  //calls printCard method by passing getRandomCard method as argument to it to get the card

       NoOfPicks++;   //adds 1 to pick count

       if (card.contains("Spades") && !spades) {  //if that random card is a card of Spades and spades is not false

           deck[index++] = card;  //add that card to the index position of deck

           spades = true;  //sets spades to true

       } else if (card.contains("Hearts") && !hearts) {  //if that random card is a card of Hearts and hearts is not false

           deck[index++] = card;  

           hearts = true;   //sets hearts to true

       } else if (card.contains("Diamond") && !diamonds) {  //if that random card is a card of Diamond and diamonds is not false

           deck[index++] = card;

           diamonds = true;  //sets diamonds to true

       } else if (card.contains("Clubs") && !clubs) {  if that random card is a card of Clubs and clubs is not false

           deck[index++] = card;

           clubs = true;         }     }   //sets clubs to true

   for (int i = 0; i < deck.length; i++) {  //iterates through the deck i.e. card sequence array

       System.out.println(deck[i]);     }  //prints the card number in deck

   System.out.println("Number of picks: " + NoOfPicks);  }   //prints number of picks

public static int getRandomCard() {  //gets random card

   return (int) (Math.random() * 52); }   //generates random numbers of 52 range

public static String printCard(int cardNo) {   //displays rank number and suit

   String[] suits = { "Spades", "Hearts", "Diamonds", "Clubs", };  //array of suits

   String[] rankCards = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10",

           "Jack", "Queen", "King" };   //array of rank

  int suitNo = cardNo / 13;  //divides card number by 13 and stores to suitNo

 int rankNo = cardNo % 13;   //takes modulo of card number and 13 and store it to rankNo

   return rankCards[rankNo] + " of " + suits[suitNo];  }}  //returns rankCard at rankNo index and suits at suitNo index

Explanation:

The program is explained in the comments attached with each line of code. The screenshot of the program along with its output is attached.

8 0
3 years ago
What are the types of technology that is use in education and what are their usages​
hjlf
Computers and Tablets I think
5 0
3 years ago
Which heading function is the biggest?<br> 1. h1<br> 2. h2<br> 3. h3
sattari [20]

Answer:

h3

Explanation:

sub to Thicc Panda on YT

6 0
2 years ago
Read 2 more answers
True / False<br> General purpose registers can be read and written by ML programs
Oduvanchick [21]

Answer: False

Explanation:

  General purpose register cannot be read and written by the Ml program because when ever the instruction decode the input and output unit are invoke for data to read in the memory and it can written to the output device from the memory. General purpose register stored both the addresses and the data in the file. In some cases ML only reads with the hep of special algorithm function.

6 0
2 years ago
Other questions:
  • When you use the ip address of the web server, the correct site is displayed?
    15·1 answer
  • Advancements in technology that might be helpful for individuals who need accommodations to perform computer tasks include _____
    15·2 answers
  • A network technician is assisting the security team with some traffic captures. The security team wants to capture all traffic o
    9·1 answer
  • For which punctuation symbol will you use the ring finger of your right hand?
    9·1 answer
  • True or false: within a database, fields can be added, deleted and edited but never moved.
    11·1 answer
  • Blank are back and forth movement of matter that create sound​
    15·1 answer
  • What are digital forensic techniques? A. Identifying, extracting, and evaluating evidence obtained from digital media such as co
    11·1 answer
  • Write a function that takes as input a single integer parameter n and computes the nth Fibonacci Sequence number. The Fibonacci
    8·1 answer
  • Which term describes a visual object such as a picture a table or text box
    15·2 answers
  • Award documentation is typically required to be prepared and submitted within how long after the end of a project period:_____.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!